package com.atguigu.gmall.task;

import com.atguigu.gmall.rabbit.constants.MQConst;
import com.atguigu.gmall.rabbit.util.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: lx
 * @Time: 14:34
 * @Description:
 */
@Component
@EnableScheduling //开启定时器
public class Task0 {


    @Autowired
    private RabbitService rabbitService;
    //定时任务  cron表达式  半夜0点
    //@Scheduled(cron = "0 0 0 * * ?")
    @Scheduled(cron = "0/5 * * * * ?") //每隔5S执行一次
    public void task0(){
        System.out.println("铃响了");
        //发MQ
        rabbitService.sendMessage(MQConst.EXCHANGE_DIRECT_TASK,
                MQConst.ROUTING_TASK_1,"1111");
    }

}
